//
//  OneToastController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/18.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "OneToastController.h"
#import "TwoToastController.h"
#import "TthereToastController.h"

@interface OneToastController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;
@end

@implementation OneToastController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHidenNaviBar = YES;
    ViewRadius(self.view, 4);
    [self.view addSubview:self.listView];
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}
#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSoure.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OneToastCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OneToastCell class])];
    cell.modeDic = self.dataSoure[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 1) {
        [self.navigationController pushViewController:[TwoToastController new] animated:YES];
    }else if (indexPath.row == 3){
        [self.navigationController pushViewController:[TthereToastController new] animated:YES];
    }
    if (indexPath.row == 0) {
        BlockSafeRun(self.notInterestedBlock);
        [self backBtnClicked];
    }
    if (indexPath.row == 2) {
        [self backBtnClicked];
    }
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[UITableView new];
        _listView.delegate =self;
        _listView.dataSource = self;
        _listView.scrollEnabled = NO;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[OneToastCell class] forCellReuseIdentifier:NSStringFromClass(OneToastCell.class)];
        _listView.separatorColor = SeparatorColor;
        _listView.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
    }
    return _listView;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        NSDictionary * oneDic = @{@"leftImage":@"不感兴趣_tost",@"topName":@"不感兴趣",@"botmName":@"减少这类内容",@"isMore":@(NO)};
        NSDictionary * twoDic = @{@"leftImage":@"反馈垃圾内容",@"topName":@"反馈垃圾内容",@"botmName":@"减少这类内容",@"isMore":@(YES)};
        
        NSDictionary * thereDic = @{@"leftImage":@"拉黑作者",@"topName":@"拉黑作者：用户名",@"botmName":@"",@"isMore":@(NO)};
        NSDictionary * foureDic = @{@"leftImage":@"屏蔽",@"topName":@"屏蔽",@"botmName":@"薯条，垃圾食品等",@"isMore":@(YES)};

        _dataSoure =[NSMutableArray array];
        [_dataSoure addObject:oneDic];
        [_dataSoure addObject:twoDic];
        [_dataSoure addObject:thereDic];
        [_dataSoure addObject:foureDic];

    }
    return _dataSoure;
}
@end

@interface OneToastCell ()
/**<#属性#>*/
@property (nonatomic,strong)UIImageView*leftImage;
/**<#属性#>*/
@property (nonatomic,strong)UILabel*topLabel;
/**<#属性#>*/
@property (nonatomic,strong)UILabel*bottomLabel;
/**<#属性#>*/
@property (nonatomic,strong)UIImageView*moreImage;
@end

@implementation OneToastCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)setModeDic:(NSDictionary *)modeDic{
    _modeDic = modeDic;
    self.topLabel.text = modeDic[@"topName"];
    self.bottomLabel.text = modeDic[@"botmName"];
    
    self.moreImage.hidden = ![modeDic[@"isMore"] boolValue];
    self.leftImage.image = IMAGE_NAMED(modeDic[@"leftImage"]);
    if (StrValid(modeDic[@"botmName"])) {
        [self.topLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.leftImage);
        }];
    }else{
        [self.topLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.leftImage);
        }];
    }
}
-(void)createUI{
    [self addSubview:self.leftImage];
    [self addSubview:self.topLabel];
    [self addSubview:self.bottomLabel];
    [self addSubview:self.moreImage];
    
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(40);
    }];
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.leftImage.mas_right).offset(16);
        make.top.mas_equalTo(self.leftImage);
    }];
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.leftImage.mas_right).offset(16);
        make.bottom.mas_equalTo(self.leftImage);
    }];
    
    [self.moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(0);
    }];
}
-(UIImageView*)leftImage{
    if(!_leftImage){
        _leftImage=[UIImageView new];
//        _leftImage.backgroundColor = KGrayColor;
        _leftImage.layer.cornerRadius = 20;
    }
    return _leftImage;
}
-(UILabel*)topLabel{
    if(!_topLabel){
        _topLabel=[UILabel new];
        _topLabel.textColor = UIColorFromRGB(0x273323);
        _topLabel.font = BOLDSYSTEMFONT(16);
        _topLabel.text = @"不感兴趣";
    }
    return _topLabel;
}
-(UILabel*)bottomLabel{
    if(!_bottomLabel){
        _bottomLabel=[UILabel new];
        _bottomLabel.textColor = UIColorFromRGB(0x959E97);
        _bottomLabel.font = SYSTEMFONT(12);
        _bottomLabel.text = @"减少这类内容";

    }
    return _bottomLabel;
}
-(UIImageView*)moreImage{
    if(!_moreImage){
        _moreImage=[UIImageView new];
        _moreImage.image = IMAGE_NAMED(@"more");
    }
    return _moreImage;
}
@end
